<?php
// Call JCAT_FriendshipTest::main() if this source file is executed directly.
if (!defined('PHPUnit_MAIN_METHOD'))
	define('PHPUnit_MAIN_METHOD', 'JCAT_FriendshipTest::main');


require_once 'PHPUnit/Framework.php';

require_once '/home/alee/Project/JeCat/JCAT0.2/trunk/JCAT.Framework_0.2.0/lib.php/Application/Backtrace/class.JCAT_Friendship.php';






class aaa
{
	function xxx($callback)
	{
		return call_user_func($callback) ;
	}
	function yyy($callback)
	{
		return call_user_func($callback) ;		
	}
	function zzz($callback)
	{
		return call_user_func($callback) ;		
	}
	
	function ccc($callback)
	{
		return call_user_func($callback) ;		
	}
	
	
	function iii()
	{
		return JCAT_Friendship::IsFriend() ;
	}
	
	static $nClassID = 0 ;
}
aaa::$nClassID = JCAT_Package::RegisterClassID('aaa',6,100) ;

class bbb
{

	function ooo($callback)
	{
		return call_user_func($callback) ;		
	}
	function ppp($callback)
	{
		return call_user_func($callback) ;		
	}
	function qqq($callback)
	{
		return call_user_func($callback) ;		
	}
	
	function ccc($callback)
	{
		return call_user_func($callback) ;		
	}
	
}

class ccc
{
	function hhh($callback)
	{
		return call_user_func($callback) ;		
	}
}
class ddd
{
	function mmm($callback)
	{
		return call_user_func($callback) ;		
	}
	function nnn($callback)
	{
		return call_user_func($callback) ;		
	}
}


function ttt($callback)
{
	return call_user_func($callback) ;		
}
function rrr($callback)
{
	return call_user_func($callback) ;		
}





function sss()
{
	return JCAT_Friendship::IsFriend() ;
}
















/**
 * Test class for JCAT_Friendship.
 * Generated by PHPUnit on 2007-12-20 at 13:41:54.
 */
class JCAT_FriendshipTest extends PHPUnit_Framework_TestCase
{
	/**
	 * Runs the test methods of this class.
	 *
	 * @access public
	 * @static
	 */
	public static function main()
	{
		require_once 'PHPUnit/TextUI/TestRunner.php';

		$suite  = new PHPUnit_Framework_TestSuite('JCAT_FriendshipTest');
		$result = PHPUnit_TextUI_TestRunner::run($suite);
	}

	/**
	 * Sets up the fixture, for example, opens a network connection.
	 * This method is called before a test is executed.
	 *
	 * @access protected
	 */
	protected function setUp()
	{
	}

	/**
	 * Tears down the fixture, for example, closes a network connection.
	 * This method is called after a test is executed.
	 *
	 * @access protected
	 */
	protected function tearDown()
	{
	}

    /**
     * @todo Implement testIsFriend().
     */
    public function testForFunction() {
        $a = new aaa() ;
        $b = new bbb() ;
        $c = new ccc() ;
        $d = new ddd() ;
		JCAT_Friendship::Clear() ;
		
		// 友元 包
		JCAT_Friendship::SetFriendlyPackage(6,'::sss') ;
		$this->assertTrue( $a->xxx('sss') ) ;
		$this->assertTrue( $a->yyy('sss') ) ;
		$this->assertTrue( $a->zzz('sss') ) ;
		$this->assertTrue( $a->ccc('sss') ) ;
		
		$this->assertFalse( $b->ooo('sss') ) ;
		$this->assertFalse( $b->ppp('sss') ) ;
		$this->assertFalse( $b->qqq('sss') ) ;
		$this->assertFalse( $b->ccc('sss') ) ;
		
		$this->assertFalse( $c->hhh('sss') ) ;
		
		$this->assertFalse( $d->mmm('sss') ) ;
		$this->assertFalse( $d->nnn('sss') ) ;
		
		$this->assertFalse( rrr('sss') ) ;
		$this->assertFalse( ttt('sss') ) ;
		
		// 友元 类
		JCAT_Friendship::SetFriendlyClass('bbb','::sss') ;
		$this->assertTrue( $a->xxx('sss') ) ;
		$this->assertTrue( $a->yyy('sss') ) ;
		$this->assertTrue( $a->zzz('sss') ) ;
		$this->assertTrue( $a->ccc('sss') ) ;
		
		$this->assertTrue( $b->ooo('sss') ) ;
		$this->assertTrue( $b->ppp('sss') ) ;
		$this->assertTrue( $b->qqq('sss') ) ;
		$this->assertTrue( $b->ccc('sss') ) ;
		
		$this->assertFalse( $c->hhh('sss') ) ;
		
		$this->assertFalse( $d->mmm('sss') ) ;
		$this->assertFalse( $d->nnn('sss') ) ;
		
		$this->assertFalse( rrr('sss') ) ;
		$this->assertFalse( ttt('sss') ) ;
		
		// 友元 方法
		JCAT_Friendship::SetFriendlyMethod('ddd','mmm','::sss') ;
		$this->assertTrue( $a->xxx('sss') ) ;
		$this->assertTrue( $a->yyy('sss') ) ;
		$this->assertTrue( $a->zzz('sss') ) ;
		$this->assertTrue( $a->ccc('sss') ) ;
		
		$this->assertTrue( $b->ooo('sss') ) ;
		$this->assertTrue( $b->ppp('sss') ) ;
		$this->assertTrue( $b->qqq('sss') ) ;
		$this->assertTrue( $b->ccc('sss') ) ;
		
		$this->assertFalse( $c->hhh('sss') ) ;
		
		$this->assertTrue( $d->mmm('sss') ) ;
		$this->assertFalse( $d->nnn('sss') ) ;
		
		$this->assertFalse( rrr('sss') ) ;
		$this->assertFalse( ttt('sss') ) ;
		
		// 友元 全局函数
		JCAT_Friendship::SetFriendlyFunction('ttt','::sss') ;
		$this->assertTrue( $a->xxx('sss') ) ;
		$this->assertTrue( $a->yyy('sss') ) ;
		$this->assertTrue( $a->zzz('sss') ) ;
		$this->assertTrue( $a->ccc('sss') ) ;
		
		$this->assertTrue( $b->ooo('sss') ) ;
		$this->assertTrue( $b->ppp('sss') ) ;
		$this->assertTrue( $b->qqq('sss') ) ;
		$this->assertTrue( $b->ccc('sss') ) ;
		
		$this->assertFalse( $c->hhh('sss') ) ;
		
		$this->assertTrue( $d->mmm('sss') ) ;
		$this->assertFalse( $d->nnn('sss') ) ;
		
		$this->assertFalse( rrr('sss') ) ;
		$this->assertTrue( ttt('sss') ) ;
    }

    /**
     * @todo Implement testIsFriend().
     */
    public function testForClass() {
        $a = new aaa() ;
        $b = new bbb() ;
        $c = new ccc() ;
        $d = new ddd() ;
		JCAT_Friendship::Clear() ;
		
		// 友元 包
		JCAT_Friendship::SetFriendlyPackage(6,'aaa::') ;
		$this->assertTrue( $a->xxx(array($a,'iii')) ) ;
		$this->assertTrue( $a->yyy(array($a,'iii')) ) ;
		$this->assertTrue( $a->zzz(array($a,'iii')) ) ;
		$this->assertTrue( $a->ccc(array($a,'iii')) ) ;
		
		$this->assertFalse( $b->ooo(array($a,'iii')) ) ;
		$this->assertFalse( $b->ppp(array($a,'iii')) ) ;
		$this->assertFalse( $b->qqq(array($a,'iii')) ) ;
		$this->assertFalse( $b->ccc(array($a,'iii')) ) ;
		
		$this->assertFalse( $c->hhh(array($a,'iii')) ) ;
		
		$this->assertFalse( $d->mmm(array($a,'iii')) ) ;
		$this->assertFalse( $d->nnn(array($a,'iii')) ) ;
		
		$this->assertFalse( rrr(array($a,'iii')) ) ;
		$this->assertFalse( ttt(array($a,'iii')) ) ;
		
		// 友元 类
		JCAT_Friendship::SetFriendlyClass('bbb','aaa::') ;
		$this->assertTrue( $a->xxx(array($a,'iii')) ) ;
		$this->assertTrue( $a->yyy(array($a,'iii')) ) ;
		$this->assertTrue( $a->zzz(array($a,'iii')) ) ;
		$this->assertTrue( $a->ccc(array($a,'iii')) ) ;
		
		$this->assertTrue( $b->ooo(array($a,'iii')) ) ;
		$this->assertTrue( $b->ppp(array($a,'iii')) ) ;
		$this->assertTrue( $b->qqq(array($a,'iii')) ) ;
		$this->assertTrue( $b->ccc(array($a,'iii')) ) ;
		
		$this->assertFalse( $c->hhh(array($a,'iii')) ) ;
		
		$this->assertFalse( $d->mmm(array($a,'iii')) ) ;
		$this->assertFalse( $d->nnn(array($a,'iii')) ) ;
		
		$this->assertFalse( rrr(array($a,'iii')) ) ;
		$this->assertFalse( ttt(array($a,'iii')) ) ;
		
		// 友元 方法
		JCAT_Friendship::SetFriendlyMethod('ddd','mmm','aaa::') ;
		$this->assertTrue( $a->xxx(array($a,'iii')) ) ;
		$this->assertTrue( $a->yyy(array($a,'iii')) ) ;
		$this->assertTrue( $a->zzz(array($a,'iii')) ) ;
		$this->assertTrue( $a->ccc(array($a,'iii')) ) ;
		
		$this->assertTrue( $b->ooo(array($a,'iii')) ) ;
		$this->assertTrue( $b->ppp(array($a,'iii')) ) ;
		$this->assertTrue( $b->qqq(array($a,'iii')) ) ;
		$this->assertTrue( $b->ccc(array($a,'iii')) ) ;
		
		$this->assertFalse( $c->hhh(array($a,'iii')) ) ;
		
		$this->assertTrue( $d->mmm(array($a,'iii')) ) ;
		$this->assertFalse( $d->nnn(array($a,'iii')) ) ;
		
		$this->assertFalse( rrr(array($a,'iii')) ) ;
		$this->assertFalse( ttt(array($a,'iii')) ) ;
		
		// 友元 全局函数
		JCAT_Friendship::SetFriendlyFunction('ttt','aaa::') ;
		$this->assertTrue( $a->xxx(array($a,'iii')) ) ;
		$this->assertTrue( $a->yyy(array($a,'iii')) ) ;
		$this->assertTrue( $a->zzz(array($a,'iii')) ) ;
		$this->assertTrue( $a->ccc(array($a,'iii')) ) ;
		
		$this->assertTrue( $b->ooo(array($a,'iii')) ) ;
		$this->assertTrue( $b->ppp(array($a,'iii')) ) ;
		$this->assertTrue( $b->qqq(array($a,'iii')) ) ;
		$this->assertTrue( $b->ccc(array($a,'iii')) ) ;
		
		$this->assertFalse( $c->hhh(array($a,'iii')) ) ;
		
		$this->assertTrue( $d->mmm(array($a,'iii')) ) ;
		$this->assertFalse( $d->nnn(array($a,'iii')) ) ;
		
		$this->assertFalse( rrr(array($a,'iii')) ) ;
		$this->assertTrue( ttt(array($a,'iii')) ) ;
    }

    /**
     * @todo Implement testIsFriend().
     */
    public function testForMethod() {
        $a = new aaa() ;
        $b = new bbb() ;
        $c = new ccc() ;
        $d = new ddd() ;
		JCAT_Friendship::Clear() ;
		
		// 友元 包
		JCAT_Friendship::SetFriendlyPackage(6,'aaa::iii') ;
		$this->assertTrue( $a->xxx(array($a,'iii')) ) ;
		$this->assertTrue( $a->yyy(array($a,'iii')) ) ;
		$this->assertTrue( $a->zzz(array($a,'iii')) ) ;
		$this->assertTrue( $a->ccc(array($a,'iii')) ) ;
		
		$this->assertFalse( $b->ooo(array($a,'iii')) ) ;
		$this->assertFalse( $b->ppp(array($a,'iii')) ) ;
		$this->assertFalse( $b->qqq(array($a,'iii')) ) ;
		$this->assertFalse( $b->ccc(array($a,'iii')) ) ;
		
		$this->assertFalse( $c->hhh(array($a,'iii')) ) ;
		
		$this->assertFalse( $d->mmm(array($a,'iii')) ) ;
		$this->assertFalse( $d->nnn(array($a,'iii')) ) ;
		
		$this->assertFalse( rrr(array($a,'iii')) ) ;
		$this->assertFalse( ttt(array($a,'iii')) ) ;
		
		// 友元 类
		JCAT_Friendship::SetFriendlyClass('bbb','aaa::iii') ;
		$this->assertTrue( $a->xxx(array($a,'iii')) ) ;
		$this->assertTrue( $a->yyy(array($a,'iii')) ) ;
		$this->assertTrue( $a->zzz(array($a,'iii')) ) ;
		$this->assertTrue( $a->ccc(array($a,'iii')) ) ;
		
		$this->assertTrue( $b->ooo(array($a,'iii')) ) ;
		$this->assertTrue( $b->ppp(array($a,'iii')) ) ;
		$this->assertTrue( $b->qqq(array($a,'iii')) ) ;
		$this->assertTrue( $b->ccc(array($a,'iii')) ) ;
		
		$this->assertFalse( $c->hhh(array($a,'iii')) ) ;
		
		$this->assertFalse( $d->mmm(array($a,'iii')) ) ;
		$this->assertFalse( $d->nnn(array($a,'iii')) ) ;
		
		$this->assertFalse( rrr(array($a,'iii')) ) ;
		$this->assertFalse( ttt(array($a,'iii')) ) ;
		
		// 友元 方法
		JCAT_Friendship::SetFriendlyMethod('ddd','mmm','aaa::iii') ;
		$this->assertTrue( $a->xxx(array($a,'iii')) ) ;
		$this->assertTrue( $a->yyy(array($a,'iii')) ) ;
		$this->assertTrue( $a->zzz(array($a,'iii')) ) ;
		$this->assertTrue( $a->ccc(array($a,'iii')) ) ;
		
		$this->assertTrue( $b->ooo(array($a,'iii')) ) ;
		$this->assertTrue( $b->ppp(array($a,'iii')) ) ;
		$this->assertTrue( $b->qqq(array($a,'iii')) ) ;
		$this->assertTrue( $b->ccc(array($a,'iii')) ) ;
		
		$this->assertFalse( $c->hhh(array($a,'iii')) ) ;
		
		$this->assertTrue( $d->mmm(array($a,'iii')) ) ;
		$this->assertFalse( $d->nnn(array($a,'iii')) ) ;
		
		$this->assertFalse( rrr(array($a,'iii')) ) ;
		$this->assertFalse( ttt(array($a,'iii')) ) ;
		
		// 友元 全局函数
		JCAT_Friendship::SetFriendlyFunction('ttt','aaa::iii') ;
		$this->assertTrue( $a->xxx(array($a,'iii')) ) ;
		$this->assertTrue( $a->yyy(array($a,'iii')) ) ;
		$this->assertTrue( $a->zzz(array($a,'iii')) ) ;
		$this->assertTrue( $a->ccc(array($a,'iii')) ) ;
		
		$this->assertTrue( $b->ooo(array($a,'iii')) ) ;
		$this->assertTrue( $b->ppp(array($a,'iii')) ) ;
		$this->assertTrue( $b->qqq(array($a,'iii')) ) ;
		$this->assertTrue( $b->ccc(array($a,'iii')) ) ;
		
		$this->assertFalse( $c->hhh(array($a,'iii')) ) ;
		
		$this->assertTrue( $d->mmm(array($a,'iii')) ) ;
		$this->assertFalse( $d->nnn(array($a,'iii')) ) ;
		
		$this->assertFalse( rrr(array($a,'iii')) ) ;
		$this->assertTrue( ttt(array($a,'iii')) ) ;
    }

}

// Call JCAT_FriendshipTest::main() if this source file is executed directly.
if (PHPUnit_MAIN_METHOD == 'JCAT_FriendshipTest::main')
	JCAT_FriendshipTest::main();
?>
